package co.yixiang.controller.manager.wechat;

import co.yixiang.modules.mp.entity.domain.YxArticleVisitLog;
import co.yixiang.modules.mp.entity.dto.YxArticleVisitLogQueryCriteria;
import co.yixiang.modules.mp.service.YxArticleVisitLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商城:微信图文浏览管理")
@RestController
@RequestMapping("api")
public class WechatArticleVisitLogController {

    private final YxArticleVisitLogService yxArticleVisitLogService;

    public WechatArticleVisitLogController(YxArticleVisitLogService yxArticleVisitLogService) {
        this.yxArticleVisitLogService = yxArticleVisitLogService;
    }


    @ApiOperation(value = "查询")
    @GetMapping(value = "/yxArticleVisitLog")
    //@PreAuthorize("hasAnyRole('admin','YXARTICLEVISITLOG_ALL','YXARTICLEVISITLOG_SELECT')")
    public ResponseEntity getYxArticles(YxArticleVisitLogQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity(yxArticleVisitLogService.queryAll(criteria, pageable), HttpStatus.OK);
    }


    @ApiOperation(value = "查询某个文章所有的浏览数据")
    @GetMapping(value = "/yxArticleVisitLog/{articleId}")
    //@PreAuthorize("hasAnyRole('admin','YXARTICLEVISITLOG_ALL','YXARTICLEVISITLOG_SELECT')")
    public ResponseEntity getArticleStats(@PathVariable(value = "articleId") Integer articleId) {
        return new ResponseEntity(yxArticleVisitLogService.queryAllByArticleId(articleId), HttpStatus.OK);
    }


    @ApiOperation(value = "修改")
    @PutMapping(value = "/yxArticleVisitLog")
    //@PreAuthorize("hasAnyRole('admin','YXARTICLEVISITLOG_ALL','YXARTICLEVISITLOG_EDIT')")
    public ResponseEntity update(@Validated @RequestBody YxArticleVisitLog resources) {
        yxArticleVisitLogService.createOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
}
